package com.gensdai.leliang.dialog;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.gensdai.leliang.R;
import com.gensdai.leliang.adapter.SortAdapter;
import com.gensdai.leliang.popupwindow.BasePopupWindow;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zsxx on 2017/7/28.
 */

public class FilterPricePopup extends BasePopupWindow {


    ListView priceList;
    private View popupView;

    SortAdapter adapter;
    private List<String> sorts;


    onPriceItemClick click;

    public FilterPricePopup(Activity context) {
        super(context);

        sorts = new ArrayList<String>();
        sorts.add("综合排序");
        sorts.add("价格由高到低");
        sorts.add("价格由低到高");


    }

    public void setOnItemClickListener(onPriceItemClick click){
        this.click = click;
    }
    public void reset(){
        adapter.setSelector(0);
        if(click != null){
            click.onResetListener(sorts.get(0)
                    .toString(),FilterPricePopup.this);
        }
    }

    public void init(){
        priceList = (ListView) popupView.findViewById(R.id.priceList);
        adapter = new SortAdapter(getContext());
        priceList.setAdapter(adapter);
        adapter.add(sorts);
        priceList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                adapter.setSelector(arg2);
                if(click != null){
                    click.onPriceSortItemClick(arg0.getItemAtPosition(arg2)
                                    .toString(),FilterPricePopup.this,arg2);
                }
//                if (itemsOnclick != null)
//                    itemsOnclick.ItemClick(arg0.getItemAtPosition(arg2)
//                                    .toString(), (arg2 + 1) + "",
//                            FilterPopupWindow.this);

            }
        });
    }

    @Override
    public View onCreatePopupView() {
        popupView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_select_price_popup, null);
        return popupView;
    }

    @Override
    public View initAnimaView() {
        return popupView.findViewById(R.id.priceList);
    }

    @Override
    protected Animation initShowAnimation() {
        return getTranslateAnimation(-(250 * 5),0, 260);
    }

    @Override
    protected Animation initExitAnimation() {
        return getTranslateAnimation(0,-(250 * 5), 260);
    }

    @Override
    public View getClickToDismissView() {
        return getPopupWindowView();
    }


    public interface onPriceItemClick{
        void onPriceSortItemClick(String t, BasePopupWindow p,int type);
        void onResetListener(String t, BasePopupWindow p);
    }
}
